<template>
  <div class="card-wrapper" :class="{ 'active': active }">
    <el-card class="image-card">
      <template #header>
        <div class="card-header">
          <span>{{ title }}</span>
          <span class="description">{{ description }}</span>
        </div>
      </template>
      
      <div class="card-body">
        <div class="image-grid">
          <div v-for="(image, index) in images" 
               :key="index" 
               class="image-container">
            <el-image
              class="image"
              :src="image.url"
              :preview-src-list="images.map(img => img.url)"
              :initial-index="index"
              :zoom-rate="1.2"
              :max-scale="7"
              :min-scale="0.2"
              fit="contain"
            />
            <div class="image-description">{{ image.description }}</div>
          </div>
        </div>
      </div>
      
      <div class="card-footer">
        <el-button size="small" type="primary" @click="$emit('version-click')">版本</el-button>
        <el-button size="small" type="success" @click="$emit('dependency-click')">依赖</el-button>
        <el-button size="small" type="warning">下载</el-button>
        <el-button size="small" type="danger" @click="handleUpload">上传</el-button>
      </div>
    </el-card>
  </div>

  <UploadDialog
    v-model:visible="uploadDialogVisible"
    :default-project-id="projectId"
    @submit="handleUploadSubmit"
  />
</template>

<script setup>
import { ref } from 'vue';
import UploadDialog from './UploadDialog.vue';

// 声明所有可能的事件
const emit = defineEmits([
  'version-click',
  'dependency-click',
  'update:visible'
]);

const props = defineProps({
  title: String,
  description: String,
  images: {
    type: Array,
    default: () => []
  },
  active: Boolean,
  projectId: {
    type: Number,
    required: true
  }
});

const uploadDialogVisible = ref(false);

const handleUpload = () => {
  uploadDialogVisible.value = true;
};

const handleUploadSubmit = (formData) => {
  console.log('Upload form data:', formData);
  // 处理上传逻辑
};
</script>

<style scoped>
.card-wrapper {
  width: 100%;
  margin-bottom: 16px;
}

.image-card {
  width: 100%;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-body {
  padding: 10px;
}

.image-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  width: 100%;
  justify-content: flex-start;
  padding: 10px;
}

.image-container {
  width: calc(25% - 1.5px);
  position: relative;
  padding-top: calc((25% - 1.5px) * 0.75);
  border-radius: 4px;
  margin-bottom: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.image {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.image-description {
  position: absolute;
  bottom: -24px;
  width: 100%;
  text-align: center;
  font-size: 12px;
  color: #666;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 4px 0;
}

.card-footer {
  padding: 10px;
  display: flex;
  justify-content: flex-start;
  gap: 8px;
}

:deep(.el-card) {
  width: 100%;
}

:deep(.el-card__body) {
  padding: 0 !important;
}

.card-wrapper.active .image-card {
  border: 2px solid var(--el-color-primary);
  box-shadow: 0 2px 12px 0 rgba(0,0,0,.1);
}

.description {
  color: #666;
  font-size: 14px;
  margin-left: 8px;
}
</style> 